import { Injectable } from '@angular/core';
import { HttpClient, HttpErrorResponse, HttpHeaders, HttpParams } from '@angular/common/http'
import { Observable, throwError } from 'rxjs';
import { catchError, retry } from 'rxjs/operators';
import { ENTRY } from '../../../enter';
import { LabelValueEntity, stateResEntity, PostRequest } from './transaction-details.entity';

@Injectable({
  providedIn: 'root'
})
export class TransactionDetailsService {
  private headers: HttpHeaders;
  constructor(private http: HttpClient) {
    this.headers = new HttpHeaders();
    this.headers.set('Content-Type', 'application/json');
  }
  private baseUrl = '/api/transaction/post';
  public postNewRecipy(from_name_: string, to_name_: string, money_: number ): Observable<stateResEntity> {
    let postData: PostRequest;
    postData = { from_name: from_name_, to_name: to_name_, money: money_, time: 6000 };
    return this.http.post<stateResEntity>(this.baseUrl, postData);
  }

  public getOptionalObject(name: string): LabelValueEntity[] {
    const children: LabelValueEntity[] = [
      {
        label: '蓝思科技',
        value: 'lansikeji'
      },
      {
        label: '华为',
        value: 'huawei'
      },
      {
        label: '京东方',
        value: 'jingdongfang'
      },
    ];
    let fin: LabelValueEntity[] = [];
    for (let i = 0; i < children.length; i++) {
      if (children[i].value != name) {
        fin.push(children[i]);
      }
    }
    return fin;
  }
}
